# -*- coding:utf-8 -*-
#商品服务层
from web import app
from bson import json_util
from flask import render_template,request
from web.service import goods_service
from web.service import reviews_service

__page_text = 'goods'

#跳转到商品数据页面
@app.route('/{0}/jumpPage'.format(__page_text),methods=['GET'])
def jumpPage():
    return render_template('{0}/goods.html'.format(__page_text))

#获取商品数据页面数据
@app.route('/{0}/getData'.format(__page_text),methods=['POST'])
def getGoodsData():
    service = goods_service.goodsService()
    return service.getData(request)

#跳转单个商品详情页面
@app.route('/{0}/jumpOneGoods/<goods_id>'.format(__page_text),methods=['GET'])
def jumpOneGoods(goods_id):
    return render_template('{0}/goodsDetail.html'.format(__page_text),goods_id=goods_id)

#获取单个商品数据
@app.route('/{0}/getOneGoods'.format(__page_text),methods=['POST'])
def getOneGoods():
    service = goods_service.goodsService()
    return service.getOneData(request.form['goods_id'])

#获取单个商品数据
@app.route('/{0}/getOneGoodsReviews'.format(__page_text),methods=['POST'])
def getOneGoodsReviews():
    reviewsService = reviews_service.reviewsService()
    return reviewsService.getPageData(request.form['goods_id'])

#获取单个商品评论数据
@app.route('/{0}/getGoodsReviews'.format(__page_text),methods=['POST'])
def getGoodsReviews():
    service = goods_service.goodsService()
    reviewsService = reviews_service.reviewsService()
    return service.getOneData(request.form['goods_id'])


#获取单个商品评论页面
@app.route('/{0}/jumpToGoodsReviews/<goods_id>'.format(__page_text),methods=['GET'])
def jumpToGoodsReviews(goods_id):
    service = goods_service.goodsService()
    data =  service.getOneData(goods_id)
    return render_template('{0}/goodsReviews.html'.format(__page_text),goods=json_util.loads(data),goods_id=goods_id)